<?php
namespace haibao\www\data\message;

class MessageBox extends \haibao\www\data\BaseMysql{

    public function __construct(){
        parent::__construct('\haibao\www\model\data\message\MessageBox');
		$this->setConfig( \haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_USER );
    }
   	public function updateMessageReadStatus($messageIds,$status){
   		
   		$messageIds = (array)$messageIds;
   		$messageIdStr = implode(',', $messageIds);
   		$str = preg_replace('/(\d+)/', '%s', $messageIdStr);
   		$sql = 'update MessageBox set IsRead=%s where Id in ('.$str.')';
   		array_unshift($messageIds, $status);
   		$this->query($sql,$messageIds);
   	}
   	
   	public function updateMessageReadStatusByUserId($userId, $messageType, $status){
   		$status == \haibao\www\model\data\message\MessageBox::READ_HAVE?$whereStatus=\haibao\www\model\data\message\MessageBox::READ_NOT:\haibao\www\model\data\message\MessageBox::READ_NOT;
   	    $this->query('update MessageBox set IsRead=%s where ToUserId=%s and MessageType=%s and IsRead=%s', array(
   	        $status, $userId, $messageType,$whereStatus
   	    ));
   	}
}